package com.example.administrator.demo1;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.support.annotation.ColorRes;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import static android.R.attr.y;


/**
 * Created by Administrator on 2017/8/29.
 */

public class MyView extends ViewGroup implements View.OnClickListener {

    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private Path mPath;
    private Point mPoint;
    private Paint mPaont;
    private int Radius = 16;
    private Context c;

    public MyView(Context context) {
//        super(context);
        this(context, null);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        c = context;
//        View view = inflate(context, R.layout.myview, null);
//        btn1 = (Button) view.findViewById(R.id.btn1);
//        btn2 = (Button) view.findViewById(R.id.btn2);
//        btn3 = (Button) view.findViewById(R.id.btn3);
//        btn4 = (Button) view.findViewById(R.id.btn4);
//        btn5 = (Button) view.findViewById(R.id.btn5);
        btn1 = new Button(c);
        mPath = new Path();
        mPoint = new Point();
        mPaont = new Paint();



        mPoint.x = 100;
        mPoint.y = 100;

        LayoutParams btn1LayoutParams = this.btn1.getLayoutParams();
        btn1.setOnClickListener(this);
        addView(btn1);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//        mPoint.set(widthMeasureSpec / 2, heightMeasureSpec / 2);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        btn1.layout(l / 2, t / 2, r / 2, b / 2);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//        canvas.drawArc((float) mPoint.x, (float) mPoint.y, (float) mPoint.x, (float) mPoint.y);
        canvas.drawCircle(mPoint.x, mPoint.y, Radius, mPaont);
    }

    @Override
    public void onClick(View v) {
        if (v instanceof Button) {
            Toast.makeText(c, "ssssssssssssssss", Toast.LENGTH_SHORT).show();
        }
    }
}
